<?php

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/6/28 0028
 * Time: 下午 5:32
 */
class ReportModel
{
    private $reportModelKeyPrefix   =   'RP/';

    public function createReportInfo($param){
        if(empty($param['uid']) ||  empty($param['reasonType']) || empty($param['type'])) {
            AC::$errorNo    =   'RPM001';
            return  FALSE;
        }
        $data = [];
        $data['uid']            =   $param['uid'];
        $data['nickname']       =   $param['nickname'];
        $data['ruid']           =   $param['rUid'];
        $data['rnickname']      =   $param['rnickname'];
        $data['reasonType']     =   $param['reasonType'];
        $data['reasonRemark']   =   isset($param['reasonRemark']) ? $param['reasonRemark'] : '';
        $data['reasonRemark']   =   UK::getstr($data['reasonRemark'], 1000, '', 1);
        $data['type']           =   $param['type'];
        $data['action']         =   isset($param['action']) ? $param['action'] : '';
        $data['content']        =   UK::JsonFormat($param['content']);
        $data['status']         =   AC::STATUS_REPORT_PENDING;
        $data['created_at']     =   AC::SERVER_TIME;
        $data['updated_at']     =   AC::SERVER_TIME;

        $key    =   $this->reportModelKeyPrefix. 0;
        $result =   Storage::addData($key, $data);

        return  $result;

    }

    /**
     * 获取用户举报某用户
     * @param $uid
     * @param $rUid
     * @param $type
     * @param $action
     * @return array
     */
    public function getReportListByUid($uid,$rUid,$type,$action){
        $key    =   $this->reportModelKeyPrefix. 0;
        $where  =   [
            'uid'   =>      $uid,
            'type'  =>      $type,
            'action'=>      $action
        ];
        if($rUid){
            $where['ruid'] = $rUid;
        }
        $result =   Storage::getConditionData($key, $where);
        return  $result;
    }

    /**
     * 获取某用户被举报列表
     * @param $rUid
     * @param $type
     * @param $action
     * @return array
     */
    public function getReportListByType($rUid,$type,$action){
        $key    =   $this->reportModelKeyPrefix. 0;
        $where  =   [
            'status'=>      1,
            'type'  =>      $type,
            'action'=>      $action
        ];
        if($rUid){
            $where['ruid'] = $rUid;
        }
        $result =   Storage::getConditionManyData($key, $where);
        return  $result;
    }

}